/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//add event function from http://www.dynarch.com/projects/calendar/
function addAnEvent(el, evname, func) {
    if (el.attachEvent) { // IE
        el.attachEvent("on" + evname, func);
    } else if (el.addEventListener) { // Gecko / W3C
        el.addEventListener(evname, func);
    } else {
        el["on" + evname] = func;
    }
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function targetNew(anchor) {
	window.open(anchor.href);
	return false;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function imageWin(imgSrc, imgW, imgH, captionTxt, node) {
	function keyboardNav(event) {
    if (event.keyCode == 37 && last) {
      remove(event);
      last.click();
    }
    if (event.keyCode == 39 && next) {
      remove(event);
      next.click();
    }
    if (event.keyCode == 27) remove(event);
  }
  window.addEventListener('keypress', keyboardNav, true);

  function remove(event) {
		backdrop.parentNode.removeChild(backdrop);
		container.parentNode.removeChild(container);
		onScroll=function(){};

		// w3c
		event.stopPropagation();
		event.preventDefault();
		// ie
		event.returnValue=false;
		event.cancelBubble=true;

    if (event.target == lastNav) last.click();
    if (event.target == nextNav) next.click();

    window.removeEventListener('keypress', keyboardNav, true);
  }

  var last = null, next = null;
  var siblings = [];
  var entry = node;
  while (entry && 'entry' != entry.className) {
    entry = entry.parentNode;
  }
  if (entry) {
    var imgs = [].slice.apply(entry.querySelectorAll('a[onclick]'));
    for (var i = 0, img = null; img = imgs[i]; i++) {
      if (img == node) {
        last = imgs[i - 1];
        next = imgs[i + 1];
        break;
      }
    }
  }

	// Create backdrop.
	var backdrop=document.createElement('div');
	with (backdrop.style) {
		background='black';
		opacity='0.66';
		filter='alpha(opacity = 50)';
		position='fixed';
		top='0';
		left='0';
		width='100%';
		height=window.innerHeight+'px';
		zIndex='9999';
	}
	addAnEvent(backdrop, 'click', remove);
	document.body.appendChild(backdrop);

	// Figure out width and height.
	var ratioW=(window.innerWidth-140)/imgW;
	var ratioH=(window.innerHeight-140)/imgH;
	var ratio=Math.min(ratioW, ratioH);
	ratio=Math.min(1.0, ratio);
	
	// Create container.
	var container=document.createElement('div');
	var w=Math.floor(imgW*ratio);
	var h=Math.floor(imgH*ratio);
	with (container.style) {
		borderRadius='1em';
		background='white';
		fontSize='0.8em';
		height=(h+60)+'px';
		left='0';
		lineHeight='0.9';
		margin='20px '+( (window.innerWidth - w - 40) / 2)+'px';
		padding='20px';
		position='fixed';
		top='0';
		width=w+'px';
		zIndex='10000';
	}
	addAnEvent(container, 'click', remove);
	document.body.appendChild(container);

	// Add image and caption.
	var img=document.createElement('img');
	img.width=w;
	img.height=h;
	img.src=imgSrc;
	container.appendChild(img);
	var caption=document.createElement('div');
	with (caption.style) {
		background='LightGrey';
		color='black';
		height='20px';
		padding='10px';
		overflow='hidden';
		marginTop='17px';
	}
	caption.innerHTML=captionTxt;
	container.appendChild(caption);

  // Add navigation.
  function navStyle(nav) {
    with (nav.style) {
      position='absolute';
      margin='1ex';
      height=(h/2 + 20)+'px';
      color='white';
      opacity='0.5';
      textShadow='0 0 8px black';
      top='20px';
      verticalAlign='middle';
      fontSize='4em';
      paddingTop=(h/2 - 20)+'px';
      cursor='pointer';
    }
  }
  if (last) {
    var lastNav = document.createElement('div');
    lastNav.textContent = "\u00AB";
    navStyle(lastNav);
    lastNav.style.left='20px';
    container.appendChild(lastNav);
  }
  if (next) {
    var nextNav = document.createElement('div');
    nextNav.textContent = "\u00BB";
    navStyle(nextNav);
    nextNav.style.right='20px';
    nextNav.style.textAlign='right';
    container.appendChild(nextNav);
  }
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function verifyPostForm(f) {
	if (''==f.subject.value) alert('You must provide a subject.');
	else if (''==f.comment.value) alert('You must enter a comment.');
	else return true;
	return false;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//frame breaker
if (top!=self) top.location.href=self.location.href;